<template>
  <div class="_wz_cent_main _wz_IncuTraiReco">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;" v-if="!seeCarData">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="从业人员">
          <i-input type="text" v-model="formDataSearch.driverName" placeholder="从业人员" clearable />
        </FormItem>
        <FormItem label="身份证号">
          <i-input type="text" v-model="formDataSearch.driverIdentifyNum" placeholder="身份证号" clearable />
        </FormItem>
        <FormItem label="联系电话" v-if="searchType">
          <i-input type="text" v-model="formDataSearch.driverPhone" placeholder="联系电话" clearable />
        </FormItem>
        <FormItem label="从业类型" v-if="searchType">
          <i-select v-model="formDataSearch.driverType" filterable placeholder="从业类型" clearable>
            <Option v-for="item in personType" :value="item.code" :key="item.code">{{item.value}}</Option>
          </i-select>
        </FormItem>
        <FormItem label="驾乘车辆" v-if="searchType">
          <i-input type="text" v-model="formDataSearch.driverVehiclePlate" placeholder="驾乘车辆" clearable />
        </FormItem>
        <FormItem label="培训周期" prop="wzYearMonth" v-if="searchType">
          <DatePicker type="month" v-model="formDataSearch.wzYearMonth" placeholder="请选择年月"></DatePicker>
        </FormItem>
        <FormItem label="培训情况" v-if="searchType">
          <i-select v-model="formDataSearch.finishState" filterable placeholder="培训情况" clearable>
            <Option value="0">未开始</Option>
            <Option value="1">已完成</Option>
            <Option value="2">进行中</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer title="培训概况" v-model="value1" width="950" :draggable="true">
      <Card dis-hover :bordered="true" style="margin:10px 0;">
        <p slot="title">基本信息</p>
        <div>
          <div style="margin:0 0 10px 0;position: relative;">
            <div style="margin:0 10px 0 0;float: left;margin: 0px 10px 0px 0px;display: block;width: 100px;height: 132px;text-align: center;line-height: 60px;border: 1px solid transparent;border-radius: 4px;overflow: hidden;background: #fff;position: relative;box-shadow: 0 1px 1px rgba(0, 0, 0, .2);">
              <viewer style="width: 100%;height: 100%;">
                <img style="width: 100%;height: 100%;" :src="!!dynamicTitle.driverAvatar?apiUrl.imgUrl+dynamicTitle.driverAvatar:'../../../assets/xxwc.png'" @error="public.imgDispose" />
              </viewer>
            </div>
            <div class="_wz_userData">
              <div style="line-height: 33px;height: 33px;">从业人员：{{dynamicTitle.driverName}}</div>
              <div style="line-height: 33px;height: 33px;">驾乘车辆：{{dynamicTitle.driverVehicleNo}}</div>
              <div style="line-height: 33px;height: 33px;">从业类型：{{dynamicTitle.driverTypeName}}</div>
              <div style="line-height: 33px;height: 33px;">身份证号：{{dynamicTitle.driverIdentifyNum}}</div>
            </div>
            <h6 style="clear: both;"></h6>
          </div>
        </div>
      </Card>
      <Table v-if="value1" stripe ref="table5" highlight-row @on-current-change="highlightRow" :loading="loading5" border :columns="columns5" :data="data5"></Table>
      <viewLearningRecords v-if="recordDetails" :highlightRowData="highlightRowData"></viewLearningRecords>
    </Drawer>
    <Drawer :title="dynamicTitle.driverName + '学员课程打印'" v-model="prinLearningType" width="900" :draggable="true">
      <learningRecord v-if="prinLearningType" :selectData="dynamicTitle"></learningRecord>
    </Drawer>
    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>
  import viewLearningRecords from './viewLearningRecords.vue'
  import wzTbale from "../../../components/table/table";
  import learningRecord from "./learningRecord";

  export default {
    props: ['seeCarData'],//接收来自父组件的数据
    components: {
      viewLearningRecords,//学习详细
      wzTbale,//列表
      learningRecord,//学习记录 打印
    },
    data() {
      return {
        spinShow:false,//本页加载
        searchType:false,//搜索条件
        subDeptList: [],//运输企业
        prinLearningType: false,//打印单学员学习记录
        learningRecord,//学习记录 打印
        recordDetails: false,//记录详情
        dynamicTitle: "",//随堂和学习记录 title
        value1: false,//随堂测验成绩
        personType: [],//从业类型
        highlightRowData: {},//查看一个人一个课件的详情
        tableData: {
          url: this.apiUrl.educateTrainPlanTrainCourseStudentPlanPageList,//请求地址
          method: 'post',//请求方式
          where: {
            driverIdentifyNum:!!this.seeCarData?this.seeCarData.driverIdentifyNum:'',
            createYear:!!this.seeCarData?this.public.timeFormatting(this.seeCarData.wzYearMonth, "yyyy"):'',
            createMonth:!!this.seeCarData?this.public.timeFormatting(this.seeCarData.wzYearMonth, "MM"):'',
          },//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '从业人员', key: 'driverName', minWidth: 90},
            {title: '从业类型', key: 'driverTypeName', minWidth: 100},
            {title: '驾乘车辆', key: 'driverVehicleNo', minWidth: 100},
            // {title: '联系电话', key: 'driverPhone', minWidth: 120},
            // {title: '身份证号', key: 'driverIdentifyNum', minWidth: 160},
            {
              title: '培训周期', key: '', minWidth: 120, render: (h, params) => {
                return h('span', params.row.trainCourseStudentPlanCreateYear + "年" + params.row.trainCourseStudentPlanCreateMonth + "月");
              }
            },
            {title: '培训课程', key: 'trainCourseStudentPlanName', minWidth: 200},
            {title: '培训类型', key: 'trainCourseStudentPlanTypeName', minWidth: 100},
            {title: '培训方向', key: 'trainCourseStudentPlanDirectionName', minWidth: 100},

            {
              title: '培训情况', key: '', minWidth: 130, render: (h, params) => {
                return h('Tag', {
                  props: {
                    type: 'dot',
                    color: (params.row.trainCourseStudentPlanFinish == 0) ? "" : (params.row.trainCourseStudentPlanFinish == 1) ? "success" : "warning"
                  }
                }, (params.row.trainCourseStudentPlanFinish == 0) ? "未开始" : (params.row.trainCourseStudentPlanFinish == 1) ? "已完成" : "进行中");
              }
            },
            {
              title: '培训进度', key: '', minWidth: 90, render: (h, params) => {
                return h('span', params.row.trainCourseStudentPlanFinishedNumber + "/" + params.row.trainCourseStudentPlanMaterialNumber);
              }
            },
            {
              title: '随堂测验', key: '', minWidth: 140, render: (h, params) => {
                return h('Tag', {
                  props: {
                    type: 'dot',
                    color: (params.row.trainCourseStudentPlanExam == 0) ? "default" : (params.row.trainCourseStudentPlanExamState == 0) ? "" : (params.row.trainCourseStudentPlanExamState == 1) ? "success" : "error"
                  }
                }, (params.row.trainCourseStudentPlanExam == 0) ? "未添加" : (params.row.trainCourseStudentPlanExamState == 0) ? "未开始" : (params.row.trainCourseStudentPlanExamState == 1) ? "考试及格" : "不及格");
              }
            },

            {title: '运输企业', key: 'deptName', minWidth: 260},
            {
              title: '操作', fixed: 'right', width: 120,
              render: (h, params) => {
                let operationButtons = [];
                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.indiLear(params.row)
                    }
                  }
                }, "查看"))
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.dynamicTitle = params.row
                      this.prinLearningType = true;
                    }
                  }
                }, "打印"))
                return operationButtons;

              }
            }
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },

        },



        formDataSearch: {},
        loading5: true,
        columns5: [
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '课题名称', key: 'materialTrainName', minWidth: 160},
          {
            title: '培训情况', key: '', minWidth: 160, render: (h, params) => {
              return h('Tag', {
                props: {
                  type: 'dot',
                  color: (params.row.trainCourseStudentPlanTaskFinish == 0) ? "" : (params.row.trainCourseStudentPlanTaskFinish == 1) ? "success" : "warning"
                }
              }, (params.row.trainCourseStudentPlanTaskFinish == 0) ? "未开始" : (params.row.trainCourseStudentPlanTaskFinish == 1) ? "已完成" : "进行中");
            }
          },
          {
            title: '开始时间', key: 'trainCourseStudentPlanTaskBeginTime', minWidth: 180, render: (h, params) => {
              return h('span', (!!params.row.trainCourseStudentPlanTaskBeginTime) ? params.row.trainCourseStudentPlanTaskBeginTime : "--");
            }
          },
          {
            title: '结束时间', key: 'trainCourseStudentPlanTaskEndTime', minWidth: 180, render: (h, params) => {
              return h('span', (!!params.row.trainCourseStudentPlanTaskEndTime) ? params.row.trainCourseStudentPlanTaskEndTime : "--");
            }
          },
        ],
        data5: [],
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态

    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;

      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })

      //从业类型
      that.axios.post(that.apiUrl.systemDictSystemDictList, {type: 'person_type'}).then(res => {
        if (!!res) {
          that.personType = res.data.data;
        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
    methods: {//执行的方法
      //个人学习
      indiLear(data) {
        let that = this;
        that.spinShow = true;
        that.axios.post(that.apiUrl.educateTrainPlanTrainCourseStudentPlanTaskList, {studentPlanUuid: data.uuid}).then(res => {
          that.spinShow = false;
          if (!!res) {
            that.value1 = true;
            that.dynamicTitle = data;
            that.data5 = res.data.data;
            that.loading5 = false;
            that.$nextTick(function () {
              if (res.data.data.length > 0) {
                that.$refs.table5.$refs.tbody.clickCurrentRow(0);
              }
              that.recordDetails = true;
            })
          }
        }).catch(err => {
          console.log('失败', err);
        })
      },
      //搜索
      searchSubmit() {

        this.formDataSearch.createYear = !!this.formDataSearch.wzYearMonth?this.public.timeFormatting(this.formDataSearch.wzYearMonth, "yyyy"):'';
        this.formDataSearch.createMonth = !!this.formDataSearch.wzYearMonth?this.public.timeFormatting(this.formDataSearch.wzYearMonth, "MM"):'';

        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
      highlightRow(news, old) {
        this.highlightRowData = news;
      },
    },
    watch: {//监听

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>

<style lang="less">
  ._wz_IncuTraiReco {
    height: 100%;
    display: flex;
    flex-direction: column;

  }

</style>
